<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Jugador extends CI_Model {
	private $table = 'jugador';
	
	function __construct(){
		parent::__construct();
	}
	
	function login($username, $password){
		$this->db->select('id, username, password');
		$this->db->from($this->table);
		$this->db->where('username',$username);
		$this->db->where('password',MD5($password));
		
		$query = $this->db->get();
		
		if($query->num_rows() == 1){
			return $query->row();
		}else{
			return FALSE;
		}
	}
	function all(){
//		$this->db->select('id, username, nombre, apellido, rol, imagen, descripcion');
//		$this->db->from($this->table);
//		$this->db->where('id',$id);
		return $this->db->get($this->table)->result();
	}
	function id($id){
//		$this->db->select('id, username, nombre, apellido, rol, imagen, descripcion');
//		$this->db->from($this->table);
		$this->db->where('id',$id);
		$query = $this->db->get($this->table);
		if($query->num_rows() > 0)	
			return $query->row();
		else return FALSE; 
	}
	function insert($jugador){
		$this->db->insert($this->table, $jugador);
		if($this->db->affected_rows())
			return $this->db->insert_id();
		else return 0;
	}
	function update($jugador, $id){
		$this->db->where('id', $id);
		$this->db->update($this->table, $jugador);
		return $this->db->affected_rows();
	}
	function delete($id){
		$this->db->delete($this->table, array('id' => $id));
		return $this->db->affected_rows();
	}
}
